using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;

namespace ThatsMeSDK.Core
{
	/// <summary>
	/// Xml Data Provider for the Core
	/// </summary>
	internal class XmlDataProvider : IDataProvider
	{
        public event LoadDataCompleted LoadDataCompleted;
		
		/// <summary>
		/// Creates a new instance of XmlDataProvider
		/// </summary>
		internal XmlDataProvider()
		{
		}

        void fetcher_DownloadStringCompleted(object sender, LoadStringCompletedEventArgs e, ServiceHandlerMethod c, object Tag)
        {
            XmlDocument xmldoc = new XmlDocument();

            string xmlData = e.Data;
            xmldoc.LoadXml(xmlData);

            this.LoadDataCompleted(this, new LoadDataCompletedEventArgs(xmldoc, Tag), c, Tag);
        }
		
		/// <summary>
		/// Load Xml data from the TM Api
		/// </summary>
		/// <param name="contentUri">Uri to the content you want to fetch</param>
		/// <returns>XmlDocument Object with the Data</returns>
        public void LoadData(Uri contentUri, ServiceHandlerMethod c, object Tag)
		{
            VBrowser fetcher = new VBrowser(20000);
            fetcher.LoadStringCompleted += new LoadStringCompleted(fetcher_DownloadStringCompleted);
            fetcher.GetRequest(contentUri, c, Tag);
		}
	}
}
